
import XlsxData from "./XlsxData";
import { XlsxType } from "./Define";
export default class XlsxDataManager  {

    private dataMap = {};

    constructor(){

    }

    addFile(json: any,fileName?:string){
        if(!json){
           // console.log(" init file res is null",fileName)
            return;
        }
        // console.log(" xslx manager add file json ",json)
        if(json.type == XlsxType.TEMPLATE){
            let room = json.data;
            for (const key in room) {
                this.dataMap[key] = new XlsxData(room[key]);
            }
        }else{
            if(fileName){
                let key = fileName;
                if(fileName.indexOf('/') >= 0){
                    key = fileName.match(/\/(\S*)\./)[1];
                }
                // console.log(' add File key is ',key," fileName ",fileName)
                this.dataMap[key] = new XlsxData(json);
            }else{
                console.error('不是合成表，fileName 不能为空 ')
            }

        }
       
    }

    get(fileName:string):XlsxData{
        let key = fileName;
        if(fileName.indexOf('/') >= 0){
            key = fileName.match(/\/(\S*)\./)[1];
        }
        let data = this.dataMap[key];
        if(!data){
            console.error(' config error get fileName ',fileName ,key)
            return null;
        }
        return data;
    }

    getKey(fileName:string){
        if(fileName.indexOf('/') >= 0){
            let temp = fileName.split('/')
            if(temp.length == 2){
                
            }
        }else{
            return fileName;
        }
    }

    clear(){
        this.dataMap = {};
    }

}
